 <!--
* description: 维修收款查询
* author: chenjingwen
* createdDate: 2021-2-24
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import Vue from "vue";
import api from "./api";
import { exportExcel } from "@/utils/exportExcel";

export default {
  name: "MaintenanceCollection",

  components: {
    OneTableTemplate,
    // Edit: () => import("./edit"),
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: api.queryDataUsingPOST_6,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey2",
          size: "small",
          name: "export",
          clickEvent: () => {
            exportExcel.call(this, api.exportStore.APIUrl);
          }, // 导出
          text: "导出",
          position: "left",
        },

        {
          compKey: "btnKey3",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "到店日期：",
                codeField: "repairTimeStart,repairTimeEnd",
                component: () =>
                  import("@/components/org/datePicker/datePicker.vue"),
                dateType: "daterange",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey2",
                labelName: "结算申请日期：",
                codeField: "submitBalanceDateStart,submitBalanceDateEnd",
                component: () =>
                  import("@/components/org/datePicker/datePicker.vue"),
                dateType: "daterange",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey3",
                labelName: "派工单号：",
                codeField: "repairOrderCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey4",
                labelName: "车牌号：",
                codeField: "carLicense",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey5",
                labelName: "VIN码：",
                codeField: "vin",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },
              {
                compKey: "compKey6",
                labelName: "送修人：",
                codeField: "repairMan",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },
              {
                compKey: "compKey7",
                labelName: "送修人电话：",
                codeField: "repairTel",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false,
              },
              {
                compKey: "compKey8",
                labelName: "服务顾问：",
                codeField: "empCode",
                component: () => import("@/components/org/commonSelect"),
                oFields: "saEmpId,empName",
                customObj: {
                  api: api.serviceConsultant,
                },
                isMust: false,
              },
              // {
              //   compKey: 'compKey8',
              //   labelName: '服务顾问：',
              //   codeField: 'empCode',
              //   component: () => import('@/components/org/commonSelect'),
              //   oFields: 'empCode,empName',
              //   customObj: {
              //     api: api.serviceConsultant
              //   },
              // customObj: {
              //   api: {
              //     APIUrl: '/mp/e3sh/aftersale/WorkOrderManagementService/serviceConsultant.do'
              //   },
              //   selectType: '1'
              // },
              //   type: 'dropdownList',
              //   isMust: false,
              // }
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "controlBtn",
                label: "操作",
                width: 140,
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "查看",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => {
                      this.$router.push({
                        name: "maincollectiondetil",
                        params: {
                          row: this.$utils.deepCopy(
                            this.$refs["multipleTable"].list[index]
                          ),
                        },
                      });
                    },
                  },
                  {
                    compKey: "propKey2",
                    labelName: "撤销申请",
                    rowFileds: "show:repairOrderStatus--50",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => this.cancelAudit(index),
                  },
                ],
              },
              {
                prop: "repairOrderCode",
                label: "派工单号",
                width: 140,
              },
              {
                prop: "carLicense",
                label: "车牌号",
              },
              {
                prop: "custName",
                label: "车主姓名",
              },
              {
                prop: "custTel",
                label: "车主电话",
                width: 140,
              },
              {
                prop: "repairTime",
                label: "到店时间",
                width: 140,
              },
              {
                prop: "repairMan",
                label: "送修人",
              },
              {
                prop: "repairTel",
                label: "送修人电话",
                width: 140,
              },
              {
                prop: "vin",
                label: "VIN码",
                width: 140,
              },
              {
                prop: "repairDueAmount",
                label: "客户费用",
              },
              {
                prop: "insuranceAmount",
                label: "保险费用",
              },
              {
                prop: "claimAmount",
                label: "索赔费用",
              },
              {
                prop: "dlrAmount",
                label: "内部费用",
              },
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          repairTimeStart: "",
          repairTimeEnd: "",
          submitBalanceDateStart: "",
          submitBalanceDateEnd: "",
          repairOrderCode: "",
          carLicense: "",
          vin: "",
          repairMan: "",
          repairTel: "",
          empCode: "",
          // saEmpId: '',
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },
  watch: {
    "$route.params": function (val) {
      if (val.isOver) {
        this.queryTable();
      }
    },
  },

  mounted() {
    // 列表查询
    this.queryTable(1);
  },
  methods: {
    cancelAudit(index) {
      this.$confirm("确定要撤销申请吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          const queryObj = {
            // 保存需要传 type="mutation"
            type: "mutation",
            apiConfig: api.applicationCanceled,
            // 条件/实体参数（变量），根据typeParam中的定义配置
            variables: {
              repairOrderCode:
                this.$refs.multipleTable.list[index].repairOrderCode,
              repairOrderId: this.$refs.multipleTable.list[index].repairOrderId,
              updateControlId:
                this.$refs.multipleTable.list[index].updateControlId,
            },
          };
          // 转换了中台请求格式数据
          var paramD = this.$getParams(queryObj);
          this.$requestAPI(paramD).then((response) => {
            if (response.result == "1") {
              this.$message({
                message: response.msg,
              });
            } else {
              this.$message({
                message: response.msg,
              });
            }
            this.queryTable(1);
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
    edit(index) {
      this.editPopupsState = "edit";
      this.editPopupsVisible = true;
      this.editRowData = this.$refs["multipleTable"].list[index];
    },
    close() {
      this.editPopupsVisible = false;
      this.queryTable(1);
    },
  },
};
</script>
